<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'
const dataitem = ref(JSON.parse(localStorage.getItem('dataitem')) || [])
console.log(dataitem.value)
const q1 = Math.round(Math.random() * 999999)
const q6 = Math.round(Math.random() * 20)
console.log(q6)

const dataJq = ref([])
const getData = async () => {
  await axios
    .get('/api/flag', {
      params: {
        pageCode: 1,
        pageSize: 10,
      },
    })
    .then(res => {
      dataJq.value = res.data.data.slice(0, 50)
      const map = new Map()
      const newArr = dataJq.value.filter(
        v => !map.has(v.banviewstate) && map.set(v.banviewstate, v),
      )
      dataJq.value = newArr
      console.log(dataJq.value)
    })
}
getData()

let activeIndex = ref(JSON.parse(localStorage.getItem('index')) || [])
const handleIndex = index => {
  localStorage.setItem('index', JSON.stringify(index + 1))
  location.reload()
}
console.log(activeIndex)
</script>

<template>
  <div class="box">
    <div class="top">
      <div class="img"><img :src="dataitem.doctorimage" alt="" /></div>
      <div class="name">{{ dataitem.doctorname }}</div>
      <div class="title">选择一面锦旗，感谢下医生对您健康帮助吧~</div>
    </div>
    <div class="jqtab">
      <div class="jq">
        <img
          :class="index + 1 === activeIndex ? 'active' : ''"
          @click="handleIndex(index)"
          v-for="(item, index) in dataJq"
          :key="index"
          :src="item.banviewimage"
          alt=""
        />
      </div>
      <div class="com">
        <span class="rs">{{ q1 }}人已送</span>
        <img
          :class="index + 1 === activeIndex ? '' : 'y'"
          @click="handleIndex(index)"
          v-for="(item, index) in dataJq"
          :key="index"
          :src="item.banviewimage"
          alt=""
        />
        <p
          class="price"
          :class="index + 1 === activeIndex ? '' : 'y'"
          @click="handleIndex(index)"
          v-for="(item, index) in dataJq"
          :key="index"
        >
          {{ item.banviewstate }}
          <span class="se">￥{{ q6 }}.00</span>
        </p>
      </div>
    </div>
    <van-button
      style="width: 95%; margin-left: 2.5%; color: #000"
      to="zf"
      color="#ffc641"
      type="primary"
      block
      >立即送出</van-button
    >
  </div>
</template>

<style scoped lang="scss">
.box {
  font-size: 0.3rem;
  width: 100%;
  height: 93%;

  .top {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
    .img,
    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
    }

    .name {
      margin: 10px 0;
    }

    .title {
      margin-bottom: 10px;
      color: #a4a4a4;
    }
  }

  .jqtab {
    width: 100%;
    margin-bottom: -1rem;
    .jq {
      width: 100%;
      display: flex;
      justify-content: space-around;
      img {
        width: 50px;
        height: 80px;
        background-color: #d8d6d6;
      }
      .active {
        border: 1px solid #ff9900;
        border-radius: 10px;
      }
    }

    .com {
      width: 100%;
      height: 400px;
      position: relative;
      text-align: center;

      .price {
        margin-top: 20px;
      }

      .rs {
        float: left;
        font-size: 0.25rem;
        background-color: #efefef;
        border-radius: 5px;
        padding: 2px 5px;
        position: absolute;
        left: 20px;
        top: 20px;
      }

      img {
        width: 215px;
        height: 270px;
        margin-top: 20px;
      }
      .y {
        display: none;
      }

      .se {
        color: #ff9900;
      }
    }
  }
}
</style>
